package com.gxa.controller;

import com.gxa.pojo.Cvm;
import com.gxa.pojo.Fative;
import com.gxa.pojo.Goods;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Created with IntelliJ IDEA.
 * User: hw
 * Date: 2020/11/26 21:34
 * Description:
 * Version: V1.0
 */
@RestController
@RequestMapping("/fative")
@Api(value = "助力活动管理",tags = "助力活动管理API")
public class FativeController {

    @Autowired(required = false)
    private ResponseData responseData;


    @RequestMapping(value = "/queryFative",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查询助力活动信息",notes = "查询助力活动信息",httpMethod = "GET")
    public ResponseData queryFative(){
        Fative fative = new Fative();
        Goods goods = new Goods();

        try {
            fative.setFativeStart(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-01 08:12:12"));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        try {
            fative.setFativeLast(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-10 08:12:12"));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        fative.setSnapNum(2);
        fative.setFactiveStatu(1);
        goods.setGoodsName("测试商品类");
        fative.setGoods(goods);
        if (fative != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(fative);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateFativeById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID修改助力活动信息",notes = "根据ID修改助力活动信息",httpMethod = "POST")
    public ResponseData updateFativeById(Integer factiveId){

        if (factiveId > 0){
            responseData.setCode(200);
            responseData.setMsg("修改成功");
        }else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/delFactiveById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID删除助力活动信息",notes = "根据ID删除助力活动信息",httpMethod = "POST")
    private ResponseData delFactiveById(Integer factiveId){

        if (factiveId > 0){
            responseData.setCode(200);
            responseData.setMsg("删除成功");
        }else {
            responseData.setCode(500);
            responseData.setMsg("删除失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/addFactive",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "添加助力活动信息",notes = "添加助力活动信息",httpMethod = "POST")
    private ResponseData addFactive(Fative fative){

        if (fative != null){
            responseData.setCode(200);
            responseData.setMsg("添加成功");
        }else {
            responseData.setCode(500);
            responseData.setMsg("添加失败");
        }
        return  responseData;
    }

    @RequestMapping(value = "/queryCvm",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查询卡券信息",notes = "查询卡券信息",httpMethod = "GET")
    public ResponseData queryCvm(){
        Cvm cvm = new Cvm();
        Goods goods = new Goods();
        cvm.setCvmId(1);
        cvm.setCvmRn("卡卷1");
        cvm.setCvmNo("CS0001");
        cvm.setCvmBatch(28287915);
        try {
            cvm.setCvmStart(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-12-01 09:30:17"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        goods.setGoodsName("大闸蟹礼品套装");
        cvm.setGoods(goods);
        cvm.setCvmStatus(1);
        cvm.setCvmUs(1);
        try {
            cvm.setCvmEd(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-01 06:06:06"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            cvm.setCvmEdf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-11 08:08:08"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (cvm != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(cvm);
        }else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }
}
